import service from '@/api/index.ts'

/**
 * 登录
 * @param userName
 * @param password
 * @constructor
 */
export const Login = async (userName: string, password: string) => {
	const { data, headers }: any = await service.post(`/new_mobile/auth/login`, {
		userId: userName,
		userPassword: password,
	})
	if (data.message.includes('User not Found')) {
		return { code: 401, message: '用户不存在' }
	} else if (data.message.includes('User password error')) {
		return { code: 401, message: '密码错误' }
	}
	if (data.code == 200) {
		localStorage.setItem('token', headers['ya-auth-token'])
		return data
	}
}

/**
 * 退出
 * @constructor
 */
export const Logout = async () => {
	const { data }: any = await service.post(`/new_mobile/auth/logout`)
	return data
}
